<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>检查字符串的结尾</title>
</head>

<body>
    <script type="text/javascript">
    function confirmEnding(str, target) {
        // "Never give up and good luck will find you."
        // -- Falcor
        return str.slice(str.length - target.length) === target;
    }

    confirmEnding("Bastian", "n");
    </script>
</body>

</html>